package com.lxw;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class Config {
    private Map<String, Object> args = new HashMap<>();
    @Bean
    public Queue testQueue() {
        return new Queue(MqConst.TEST_QUEUEQ, true, false, false, args);
    }



    //声明发布订阅模式的交换机
    @Bean
    public FanoutExchange fanout() {
        return new FanoutExchange(MqConst.EXCHANGE_FANOUT);
    }

    //声明发布订阅模式队列
    @Bean
    public Queue fanoutQueue1() {
        return new Queue(MqConst.FANOUT1);//队列一
    }
    //声明发布订阅模式队列
    @Bean
    public Queue fanoutQueue2() {
        return new Queue(MqConst.FANOUT2);//队列2
    }
    //将队列一绑定到交换机
    @Bean
    public Binding fanoutBinding1(FanoutExchange fanout, Queue fanoutQueue1) {
        return BindingBuilder.bind(fanoutQueue1).to(fanout);
    }

    //将队列2绑定到交换机
    @Bean
    public Binding fanoutBinding2(FanoutExchange fanout, Queue fanoutQueue2) {
        return BindingBuilder.bind(fanoutQueue2).to(fanout);
    }

    @Bean
    public Queue dirQueue1() {
        return new Queue(MqConst.DIRECT_ERR);//队列1
    }

    // 声明路由模式交换机
    @Bean
    public DirectExchange directExchange() {
        return new DirectExchange(MqConst.EXCHANGE_DIRECT);
    }

    //
    @Bean
    public Binding dirBinding2(DirectExchange directExchange, Queue dirQueue1) {
        return BindingBuilder.bind(dirQueue1).to(directExchange).with(MqConst.DIRECT_ERR);
    }

    @Bean
    public Binding dirBinding3(DirectExchange directExchange, Queue dirQueue1) {
        return BindingBuilder.bind(dirQueue1).to(directExchange).with(MqConst.DIRECT_INFO);
    }


    @Bean
    public Queue topQueue1() {
        return new Queue(MqConst.TOP_ERROR);//队列1
    }
    @Bean
    public Queue topQueue2() {
        return new Queue(MqConst.TOP_INFO);//队列1
    }
    @Bean
    public Queue topQueue3() {
        return new Queue(MqConst.TOP_WARN);//队列1
    }

    // 声明topic模式交换机
    @Bean
    public TopicExchange topicExchange() {
        return new TopicExchange(MqConst.EXCHANGE_TOPIC);
    }

    @Bean
    public Binding dirBinding4(TopicExchange topicExchange, Queue topQueue1) {
        return BindingBuilder.bind(topQueue1).to(topicExchange).with(MqConst.TOP_ERROR);
    }

    @Bean
    public Binding dirBinding5(TopicExchange topicExchange, Queue topQueue1) {
        return BindingBuilder.bind(topQueue1).to(topicExchange).with(MqConst.TOP_PR);
    }
    @Bean
    public Binding dirBinding6(TopicExchange topicExchange, Queue topQueue1) {
        return BindingBuilder.bind(topQueue1).to(topicExchange).with(MqConst.TOP_PR2);
    }
}
